package com.zzt.zt_lifecycle;

import androidx.appcompat.app.AppCompatActivity;
import androidx.lifecycle.Lifecycle;
import androidx.lifecycle.LifecycleEventObserver;

import android.os.Bundle;
import android.util.Log;
import android.view.View;

public class MainActivity extends AppCompatActivity {
    private static final String TAG = "Lifecycle  MainActivity";

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        Log.e(TAG, ">>>>> onCreate ");
        // 1. 添加自己定义的监听
        getLifecycle().addObserver(new MLifecycleV1());

        // 2. DefaultLifecycleObserver
        getLifecycle().addObserver(new MLifecycleV2());
        // 3. LifecycleEventObserver
        getLifecycle().addObserver(new MLifecycleV3());


        LifecycleEventObserver sss ;

        initView();
    }

    private void initView() {
        findViewById(R.id.button1).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                StartAct.start(v.getContext());
            }
        });
    }


    @Override
    protected void onStart() {
        super.onStart();
        Log.e(TAG, ">>>>> onStart ");
    }

    @Override
    protected void onStop() {
        super.onStop();
        Log.e(TAG, ">>>>> onStop ");
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        Log.e(TAG, ">>>>> onDestroy ");
    }

    @Override
    protected void onPause() {
        super.onPause();
        Log.e(TAG, ">>>>> onPause ");
    }

    @Override
    protected void onResume() {
        super.onResume();
        Log.e(TAG, ">>>>> onResume ");
    }

    @Override
    protected void onRestart() {
        super.onRestart();
        Log.e(TAG, ">>>>> onRestart ");
    }
}